package nix.anim.cms.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import nix.anim.cms.service.CmsContentService;
import nix.anim.common.pojo.LogAnnotation;
import nix.anim.common.pojo.NixResult;
import nix.anim.pojo.CmsContent;

/**
 * 站点管理Controller
 */
@Controller
public class CmsContentController {

	@Autowired
	private CmsContentService cmsContentService;
	
	@RequestMapping(value="/api/cms/content/list", method=RequestMethod.GET)
	@ResponseBody
	public NixResult getCmsContentList(Integer page, Integer rows, Integer cateId) {	
		// 调用服务
		NixResult result = cmsContentService.getCmsContentList(page, rows, cateId);
		return result;
	}
	
	@RequestMapping(value="/api/cms/content/save", method=RequestMethod.POST)
	@ResponseBody
	@LogAnnotation(action="新增/修改", object="内容")
	public NixResult saveCmsSite(CmsContent cmsContent, String content) {
		NixResult result = new NixResult();
		if (cmsContent.getId() == null) {
			// Add
			result = cmsContentService.addCmsContent(cmsContent, content);
		} else {
			// Update
			result = cmsContentService.updateCmsContent(cmsContent, content);
		}
		return result;
	}
	
	@RequestMapping(value="/api/cms/content/text", method=RequestMethod.GET)
	@ResponseBody
	public NixResult getCmsContentTextById(Long id) {	
		// 调用服务
		NixResult result = cmsContentService.getCmsContentTextById(id);
		return result;
	}
}
